<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/admin/style.css}" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px">
            <form class="layui-form layui-form-pane" action="">
                <input name="id" th:value="${obj?.id}" class="layui-input layui-hide"/>
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" th:value="${obj?.username}" lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="text" name="password" th:value="${obj?.password}"  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">手机号</label>
                    <div class="layui-input-block">
                        <input type="text" name="phone" th:value="${obj?.phone}"  lay-verify="required" placeholder="请输入手机号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">性别</label>

                    <div class="layui-input-block" th:style="'display:'+ @{(${obj?.sex!=null}?'none':'')}+''">
                        <input type="radio" name="sex" value="男" title="男">
                        <input type="radio" name="sex" value="女" title="女">
                    </div>

                    <div class="layui-input-block" th:style="'display:'+ @{(${obj?.sex == null}?'none':'')}+''">
                        <input type="text" th:value="${obj?.sex}" class="layui-input" disabled>
                    </div>

                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">角色</label>
                    <div class="layui-input-block">
                        <select  name="role" id="role">
                            <option selected value="">请选择</option>
                            <option  value="管理员">管理员</option>
                            <option  value="收银员">收银员</option>
                            <option  value="仓库管理员">仓库管理员</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item layui-hide">
                    <input type="button" lay-submit lay-filter="LAY-front-submit" id="LAY-front-submit" value="确认">
                </div>
            </form>
        </div>
    </div>
</div>
<script th:src="@{/static/layui/layui.js}"></script>

<script>
    layui.use(['form'],function () {
        var $ = layui.$;
        var form = layui.form;

        let roleId = '[[${obj?.role}]]';
        if(roleId!=''){
            //首先需要使用lay-value来确定需要设置哪个元素自动选择
            var select = 'dd[lay-value='+roleId+']';
            //触发点击事件，实现自动选择
            $("#role").siblings("div.layui-form-select").find('dl').find(select).click();
        }
    })
</script>
</body>
</html>